  // 为楼层表生成随机数据
  require("../models/relation")
  const mock = require("mockjs")
  const {Floor} = require("../models/Floor")
  const {Dormitory} = require("../models/Dormitory")
  const {sum} = require("../util/summation")
  Dormitory.findAll().then(data=>{
    const arr = JSON.parse(JSON.stringify(data))
    const length = arr.reduce((a,b)=>{
        return a + b.floorNum
    },0)
    let floorNumber = []
    for (const key in arr) {
        for(let i = 0; i < arr[key].floorNum; i++){
            floorNumber.push((i + 1) + '层')
        }
    }
    let roomNum = []
    for (const key in arr) {
        for(let i = 0; i < arr[key].floorNum; i++){
            roomNum.push(arr[key].roomNum)
        }
    }
    let floorCapacity = []
    for (const key in arr) {
        for(let i = 0; i < arr[key].floorNum; i++){
            floorCapacity.push(arr[key].roomNum * arr[key].fewPeople)
        }
    }
    let floorResided = [];
    for (const key in arr) {
        floorResided.push(...sum(arr[key].floorNum,arr[key].dormitoryresided))
    }

    let DormitoryId = [];
    for (const key in arr) {
        for(let i = 0; i < arr[key].floorNum; i++){
            DormitoryId.push(arr[key].id)
        }
    }
    const floorList = mock.mock({
        [`datas|${length}`]:[
            {
                "floorNumber|+1": floorNumber,
                "roomNum|+1":roomNum,
                "floorCapacity|+1":floorCapacity,
                "floorResided|+1":floorResided,
                "DormitoryId|+1":DormitoryId
            }
        ]
      }).datas
      Floor.bulkCreate(floorList).then(data=>{
        console.log(data);
      })
  })
